﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：马毅
    //
    // 文件名：ReturnGoodsOrderAdd.cs
    // 文件功能描述：新建退货单
    // 创建标识：马毅2009-05-12
    //
    // 修改标识： 
    // 修改描述： 
    //
    // 修改标识： 
    // 修改描述： 
    //
    // 审核人： 
    // 审核时间： 
    // 审核说明： 
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.Web;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
namespace HZ.DrugTrade.Web.Hospitals.SalesReturn
{
    public partial class ReturnGoodsOrderAdd : BasePage
    {
        public ReturnGoodsOrderAdd()
        {
            this.ModuleNo = Module.退货单管理.ToString();
            this.PageOperateType = OperateType.新增.ToString();
        }
        protected void Page_Load ( object sender, EventArgs e )
        {
            if (!Page.IsPostBack)
            {
                txtReturn.Text = AutoName(CurrentAccount.GetUser().Org.OrgName, "", "退货单");
            }
        }
        protected string AutoName(string username, string splitchar, string Typename)
        {
            string autoname = System.DateTime.Now.Year.ToString() + splitchar + System.DateTime.Now.Month.ToString() + splitchar +
             System.DateTime.Now.Day.ToString() + splitchar + System.DateTime.Now.Hour.ToString() + splitchar + System.DateTime.Now.Minute.ToString() + splitchar + System.DateTime.Now.Second.ToString() + System.DateTime.Now.Millisecond.ToString();
            return username + autoname + Typename;
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtReturn.Text.Trim()))
            {
                PageError("退货单名称未填！", "ReturnGoodsOrderAdd.aspx");
                return;
            }
            if ((new HZ.Common.ConvertHelper(dtReturnTime.Text.Trim()).ToDateTime)==null)
            {
                PageError("退货时间未填！", "ReturnGoodsOrderAdd.aspx");
                return;
            }
            //2009-11-20
            //if (string.IsNullOrEmpty(txtReturn.Text.Trim()))
            //{
            //    PageError("退货原因未填！", "ReturnGoodsOrderAdd.aspx");
            //    return;
            //}
            try
            {
                string _strReturnSerialID= Guid.NewGuid().ToString();
                IBLL_Purchase iPurchase = Factory.BLL_Purchase();
                ReturnMerchandise ReMerdse = new ReturnMerchandise();
                ReMerdse.ReturnName = txtReturn.Text.Trim();
                ReMerdse.ReturnTime = Convert.ToDateTime(dtReturnTime.Text.Trim());
                //ReMerdse.ReturnReason = txtReason.Text.Trim();
                ReMerdse.Remarks = txtRemarks.Text.Trim();
                ReMerdse.HospitalID = CurrentAccount.GetUser().Org.OrgID;
                ReMerdse.ReturnSerialID =_strReturnSerialID;
                ReMerdse.CreateUserID = CurrentAccount.GetUser().UserID;
                ReMerdse.ReturnAmount = 0.0M;
                int nSuccess = iPurchase.AddReturnMerchandise(ReMerdse);
                if (nSuccess == 1)
                {
                    HZ.Web.WebUtil.Alert("添加成功!",this);
                    //Response.Write("<script> window.opener.location.href=window.opener.location.href;window.close();</script>"); 
                    Response.Redirect("ReturnGoodsOrderCheck.aspx?TIDN=" + _strReturnSerialID + "&TINN=" + HttpUtility.UrlEncode(txtReturn.Text.Trim()));
        
                    return;
                }
                else
                {
                    HZ.Web.WebUtil.Alert("添加失败!",this);
                    return;
                }
            }
            catch (Exception ex)
            {
                PageError(ex.Message, "ReturnGoodsOrderAdd");
            }
        }
        
    }
}
